package 笔试;


import java.util.HashMap;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/8/7-9:26
 * @version:1.0
 * @function:
 */
public class 并查集 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        HashMap<Integer, node> hashMap = new HashMap<>();
        int n = in.nextInt();
        while (n > 0) {
            int key = in.nextInt(),a = in.nextInt(), b = in.nextInt();
            if (key == 2) {
                int  c = in.nextInt();
                int temp1 = a % c;
                int temp2 = b % c;
                if (temp1 == temp2)
                    System.out.println("YES");
                else {
                    if ((hashMap.get(temp1)!=null)&&(hashMap.get(temp1).val==hashMap.get(temp2).val))
                        System.out.println("YES");
                    else
                        System.out.println("NO");
                }
            } else {
                put(hashMap,a,b);
            }
            n--;
        }
    }

    private static void put(HashMap<Integer, node> hashMap, int a, int b) {
        if (hashMap.isEmpty()||(!hashMap.containsKey(a)&&!hashMap.containsKey(b))){
            node root = new node(a);
            hashMap.put(a,root);
            hashMap.put(b,root);
        }else {
            node anode = hashMap.get(a);
            node bnode = hashMap.get(b);
            node temp;
            if (anode==null||bnode==null){
                temp = anode==null?bnode:anode;
                hashMap.put(a,temp);
                hashMap.put(b,temp);
            }else {
                bnode.val = anode.val;
            }
        }
    }
}
class node{
    int val;
    public node(int val) {
        this.val = val;
    }
}